//
//  videoView.swift
//  YLH
//
//  Created by qinjiangtao on 2024/1/15.
//

import UIKit
import AVFoundation

class videoView: UIView {

    private var videoUrl = ""
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.backgroundColor = .clear
        videoUrl = "http://192.168.9.69/uploads/20231212/2e012fce73b903cdbb4f78e856aab35b.mp4"
        addUI()
    }
    
    private func addUI() {
        
        let videoUrl = URL(string: videoUrl)!
        let avPlayer = AVPlayer(url: videoUrl)
        avPlayer.accessibilityElementsHidden = true
        
        let playerLayer = AVPlayerLayer(player: avPlayer)//显示视频的图层
        playerLayer.frame = CGRect(x: 50, y: SCREEN_HEIGHT / 2 - 200, width: SCREEN_WIDTH - 100, height: 400)
        self.layer.addSublayer(playerLayer)
        avPlayer.play()
        
        let closeBtn = UIButton().then {
            $0.frame = CGRect(x: SCREEN_WIDTH / 2 - 20, y: SCREEN_HEIGHT / 2 + 210, width: 40, height: 40)
            $0.setImage(UIImage(named: "关闭"), for: .normal)
            $0.addTarget(self, action: #selector(closeBtnClick), for: .touchUpInside)
        }
        self.addSubview(closeBtn)
    }
    
    @objc private func closeBtnClick() {
        QINPopUpTool.sharedInstance().clear()
    }
    
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

}

